<!doctype html>
<html xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <title>分配角色</title>
    <meta charset="UTF-8">

    <script src="../../../js/jquery-2.0.3.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.min.css">
    <script src="../../../js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrapValidator.css">
    <script src="../../../js/bootstrapValidator.js"></script>
    <script src="../../../js/jquery.cookie.js"></script>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="../../../js/hostConfig.js"></script>
</head>
<body>
<div class="container kv-main">

    <div class="jumbotron">
        <h1>分配角色</h1>
        <p></p>
    </div>

    <form name="form" action="/p/add/submit" method="post" enctype="multipart/form-data" class="form-horizontal"
          id="app">


        <div class="form-group">
            <label class="col-lg-1 control-label">用户ID</label>
            <div class="col-lg-6">
                <input type="text" id="name" name="name" class="form-control" placeholder="用户id" v-model="user_id"/>
            </div>
        </div>


        <div class="form-group">
            <label class="col-lg-1 control-label">角色ID</label>
            <div class="col-lg-6">
                <input type="text" id="mobilephone" name="mobilephone" class="form-control" placeholder="角色ID"
                       v-model="role_id"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-1 control-label"></label>
            <div class="col-lg-4 col-lg-offset-1">
                <a class="btn btn-info btn-block" href="javascript:;" v-on:click="submitUserInfo">提交</a>
            </div>
        </div>
    </form>
</div>

</body>
</html>

<script>
    var app = new Vue({
        el: '#app',
        data: {
            role_id: "",
            user_id: ""
        },
        mounted() {
            this.user_id = this.$options.methods.getUrlParam('id');
        },
        methods: {
            submitUserInfo: function () {
                $.ajax({
                    type: "post",
                    url: host_tomcatR+'/userrole/add',
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    data: {
                        role_id: this.role_id,
                        user_id: this.user_id
                    },
                    success: function (data) {
                        this.ret = data;
                        if (data.code != "0000") {
                            alert(data.description);
                            console.log(data);
                        } else {
                            window.location.href = "/pages/manage/userrole/list.html";
                        }
                    },
                    error: function (xhr, type) {
                        console.log(xhr);
                    }
                });
            },
            getUrlParam: function (key) {
                var reg = new RegExp(key + '=([^&]*)');
                var results = location.href.match(reg);
                return results ? results[1] : null;
            }
        }
    });
</script>

